package com.btl.service.ai.support.tool;

import com.btl.service.ai.support.rag.generation.GenerationModelEnum;
import dev.langchain4j.agent.tool.Tool;
import dev.langchain4j.agent.tool.ToolExecutionRequest;
import dev.langchain4j.agent.tool.ToolSpecification;
import dev.langchain4j.data.message.AiMessage;
import dev.langchain4j.data.message.ToolExecutionResultMessage;
import dev.langchain4j.data.message.UserMessage;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.model.chat.request.ChatRequest;
import dev.langchain4j.model.chat.request.json.JsonObjectSchema;
import dev.langchain4j.model.chat.response.ChatResponse;
import dev.langchain4j.model.openaiofficial.OpenAiOfficialChatModel;
import dev.langchain4j.service.AiServices;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

@Slf4j
public class Tools {

    @Tool("Sums 2 given numbers")
    double sum(double a, double b) {
        return a + b;
    }

    @Tool("Returns a square root of a given number")
    double squareRoot(double x) {
        return Math.sqrt(x);
    }

    public static void main(String[] args) {

        ChatModel model = OpenAiOfficialChatModel.builder()
                .modelName(com.openai.models.ChatModel.GPT_4O_MINI)
                .baseUrl("http://139.59.125.71:3000/v1/")
                .apiKey("sk-hFTLLBHYuUuzbXOjHQmJDx1APfKrxa2ipWkk1BufXYzQQh2A")
                .build();
        interface MathGenius {

            String ask(String question);
        }

        class Calculator {

            @Tool
            double add(int a, int b) {
                return a + b;
            }

            @Tool
            double squareRoot(double x) {
                return Math.sqrt(x);
            }
        }

        MathGenius mathGenius = AiServices.builder(MathGenius.class)
                .chatModel(model)
                .tools(new Calculator())
                .build();

        String answer = mathGenius.ask("3+2等于多少");

        System.out.println(answer); // The square root of 475695037565 is 689706.486532.
    }
}
